package com.oocl.o2o.client.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.oocl.o2o.client.dao.AdvertisementDao;
import com.oocl.o2o.client.entity.Advertisement;

@Repository
public class AdvertisementDaoImpl implements AdvertisementDao {

	@PersistenceContext(name="un")
	private EntityManager manager;
	@Override
	public List<Advertisement> findAll() {
		
		String jpql = "select ad from Advertisement ad where ad.advertisementStatus = 'ON'";
		List<Advertisement> advertisements =  manager.createQuery(jpql).setMaxResults(6).getResultList();
		if(advertisements.isEmpty()) return null;
		else return advertisements;
	}

}
